﻿using System.Windows;
using ComicQ.Client.LoginServiceReference;
using ComicQ.Controller;

namespace ComicQ.Client.View
{
    /// <summary>
    /// Interaction logic for LoginView.xaml
    /// </summary>
    public partial class LoginView
    {
        public LoginView()
        {
            InitializeComponent();
        }

        private void ButtonLoginClick(object sender, RoutedEventArgs e)
        {
            if (textBoxUsername.Text.Equals("") || textBoxPassword.Password.Equals(""))
            {
                MessageBox.Show("field tidak boleh kosong");
            }
            else
            {
                var proxy = new LoginServiceClient();
                var result = proxy.CheckLogin(textBoxUsername.Text, textBoxPassword.Password);

                switch (result)
                {
                    case 1:
                        var memberController = new MemberController();
                        var newWindow = new ComicListView(memberController.GetMemberByUsername(textBoxUsername.Text));
                        newWindow.Show();
                        Close();

                        break;
                    case -1:
                        MessageBox.Show("password salah");
                        break;
                    default:
                        MessageBox.Show("username tidak ada");
                        break;
                }
            }
        }

        private void ButtonRegisterClick(object sender, RoutedEventArgs e)
        {
            var newWindow = new RegisterView();

            if (newWindow.ShowDialog() != false)
            {
            }
        }
    }
}
